﻿// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;

namespace Coding4Fun.Chair.Cockpit.Controls
{
	/// <summary>
	/// Interaction logic for MessagePanel.xaml
	/// </summary>
	public partial class MessagePanel : UserControl
	{
		public Storyboard uxSBDelay;

		public MessagePanel()
		{
			InitializeComponent();
			uxSBDelay = TryFindResource("uxSBDelay") as Storyboard;

            if (uxSBDelay != null)
                uxSBDelay.Completed += uxSBDelay_Completed;
		}

		void uxSBDelay_Completed(object sender, EventArgs e)
		{
			Hide();
		}

		/// <summary>
		/// Leaving secondsOpen set to 0 will leave the message open indefinitely
		/// </summary>
		public void Show(string messageText, int secondsOpen = 0, bool immediately = false)
		{
			uxMessageText.Text = messageText;
			VisualStateManager.GoToState(this, "ShowState", !immediately);

		    if (secondsOpen <= 0) 
                return;

		    uxSBDelay.Duration = new Duration(new TimeSpan(0, 0, secondsOpen));
		    uxSBDelay.Begin();
		}

		public void Hide(Boolean immediately = false)
		{
			VisualStateManager.GoToState(this, "HideState", !immediately);
		}
	}
}